/* -*- c++ -*-
*
* taglist.h
*
* Copyright (C) 2005 Petter Stokke <ummo@hellokitty.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef DELICIOUS_TAGLIST_H
#define DELICIOUS_TAGLIST_H

#include <klistview.h>

#include <qevent.h>

#include "bookmarkapi.h"

class TagListItem;

class TagList : public KListView
{
    Q_OBJECT
public:
    TagList( BookmarkAPI* api, QWidget* parent = 0, const char* name = "TagList" );

    TagListItem* currentTag() const;
    TagListItem* findTag( const QString& tagName ) const;
    void updateTags( Collection* _collection );

    BookmarkAPI* api() const
    {
        return m_api;
    }

signals:
    void tagsSelected( const QStringList& tags );
    void globalTagSelected( const QString& tag );
    void tagRenamed( const QString& oldTag, const QString& newTag );
    void pleaseRefresh();
    void urlDropped( const KURL& url, const QStringList& tag );

protected:
    bool acceptDrag( QDropEvent* event ) const;

protected slots:
    void slotTagRenamed( BookmarkAPIJob* job );
    void slotContextMenu( KListView*, QListViewItem*, const QPoint& );
    void slotOpenSelectedTags();
    void slotOpenCurrentTagGlobal();
    void slotRenameCurrentTag();
    void slotDropped( QDropEvent* event );

private:
    BookmarkAPI* m_api;

};

class TagListItem : public KListViewItem
{
public:
    TagListItem( TagList* parent, const QString& name, int count );

    const QString& tagName() const;
    int tagCount() const;

    void setTagName( const QString& name );
    void setTagCount( int count );

    QString text( int column ) const;
    int compare( QListViewItem* i, int col, bool ascending ) const;
    void setText( int column, const QString& text );

private:
    QString m_tagName;
    int m_tagCount;
};

#endif
